package com.tencent.sr.iris.basic.saas.service.model.activity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.activity.interfaces.enums.IsParticipatedEnum;
import com.tencent.sr.iris.basic.saas.common.enums.YesOrNoEnum;
import com.tencent.sr.iris.basic.saas.interfaces.response.activity.ActivityTaskPageResponse;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

@Data
@ApiModel(value = "活动明细导出信息")
@Slf4j
@ColumnWidth(15)
public class InviteActivityTaskExportInfo extends InviteActivityTaskBaseExportInfo {

    @ExcelProperty(value = "上级当月限量", index = 30)
    private String inviteLimit;

    @ExcelProperty(value = "是否可贡献", index = 31)
    private String canContribute;

    @ExcelProperty(value = "已占用额度", index = 32)
    private String usedInviteLimit;

    @ExcelProperty(value = "上级实时限额数", index = 33)
    private String monthInviteLimit;

    @ExcelProperty(value = "是否审核中", index = 34)
    private String auditing;

    @ExcelProperty(value = "收货时间", index = 35)
    private String orderFinishTime;

    @Override
    public void readFromSearchResponseData(ActivityTaskPageResponse response, Map<Long, String> areaMap) {
        super.readFromSearchResponseData(response, areaMap);

        if (response.getInviteLimit() != null && response.getInviteSeq() != null) {
            this.setInviteLimit(response.getInviteSeq() + "/" + response.getInviteLimit());
        }

        String yesOrNo = Arrays.asList(IsParticipatedEnum.YES.name(), IsParticipatedEnum.NO.name())
                .contains(response.getIsParticipated()) ? YesOrNoEnum.YES.getDesc() : YesOrNoEnum.NO.getDesc();
        this.setCanContribute(yesOrNo);

        this.setUsedInviteLimit(Optional.ofNullable(response.getUsedInviteLimit()).map(String::valueOf).orElse(StrUtil.DASHED));
        this.setMonthInviteLimit(Optional.ofNullable(response.getMonthInviteLimit()).map(String::valueOf).orElse(StrUtil.DASHED));
        this.setAuditing(response.getAuditing() ? YesOrNoEnum.YES.getDesc() : YesOrNoEnum.NO.getDesc());
        this.setOrderFinishTime(Optional.ofNullable(response.getOrderFinishTime())
                .map(i -> DateUtil.formatDateTime(DateUtil.date(i))).orElse(StrUtil.DASHED));
    }

}
